<template>
  <div class="search-list">
    <div class="headers">
      <Header></Header>
      <ul>
        <li
          v-for="(item, index) in searchList.data"
          :key="index"
          @click="changeTab(index)"
        >
          <div :class="searchList.currentIndex == index ? 'active' : ''">
            {{ item.name }}
          </div>
          <div class="search-filter" v-if="index !== 0">
            <i
              class="iconfont icon-shangjiantou"
              :class="item.status === 1 ? 'active' : ''"
            ></i>
            <i
              class="iconfont icon-xiajiantou"
              :class="item.status === 2 ? 'active' : ''"
            >
            </i>
          </div>
        </li>
      </ul>
    </div>
    <section>
      <ul>
        <li>
          <img src="../../assets/images/goods1.jpg" alt="" />
          <h6>茶百道的数据的数据库分四步划分少得可怜佛耳机</h6>

          <div class="price">
            <span>￥324</span>
            <div>立即购买</div>
          </div>
        </li>
        <li>
          <img src="../../assets/images/goods1.jpg" alt="" />
          <h6>茶百道的数据的数据库分四步划分少得可怜佛耳机</h6>

          <div class="price">
            <span>￥324</span>
            <div>立即购买</div>
          </div>
        </li>
        <li>
          <img src="../../assets/images/goods1.jpg" alt="" />
          <h6>茶百道的数据的数据库分四步划分少得可怜佛耳机</h6>
          <div class="price">
            <span>￥324</span>
            <div>立即购买</div>
          </div>
        </li>
      </ul>
    </section>
    <Tabbar></Tabbar>
  </div>
</template>

<script>
import Tabbar from "@/components/common/Tabbar.vue";
import Header from "@/components/search/Header.vue";
import qs from "qs";
export default {
  name: "SearchList",
  components: {
    Tabbar,
    Header,
  },
  data() {
    return {
      goodsList: [],
      searchList: {
        currentIndex: 0,
        data: [
          { name: "综合" },
          { name: "价格", status: 1, keys: "price" },
          { name: "销量", status: 0, keys: "num" },
        ],
      },
    };
  },
  created() {
    // this.searchArr = JSON.parse(localStorage.getItem("searchList")) || [];
    this.getGoodsList();
    //
  },
  computed: {
    orderBy() {
      //获取当前是哪个对象
      let obj = this.searchList.data[this.searchList.currentIndex];
      let val = obj.status == "1" ? "asc" : "dasc";
      return {
        [obj.keys]: val,
      };
    },
  },
  methods: {
    getGoodsList() {
      this.$http
        .get("searchlist")
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
      // console.log(data);
    },

    changeTab(index) {
      this.searchList.currentIndex = index;
      //点击下标对数据的那一个
      let item = this.searchList.data[index];
      //取消所有的状态值===>变为0
      // console.log(item);
      this.searchList.data.forEach((v, i) => {
        if (i !== index) {
          v.status = 0;
        }
      });
      //当前点击的改变状态
      if (index === this.searchList.currentIndex) {
        item.status = item.status == 1 ? 2 : 1;
      }
    },
  },
};
</script>

<style lang="less" scoped>
.headers ul {
  display: flex;
  margin-top: 20px;
  justify-content: space-around;
  font-size: 16px;
  li {
    display: flex;
    align-items: center;
    flex-direction: columns;
  }
}
.search-filter {
  display: flex;
  flex-direction: column;
  i {
    padding: 0 5px;
  }
}
section ul {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  li {
    display: flex;
    flex-direction: column;
    justify-items: center;
    align-items: center;
    width: 50%;
    h6 {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      width: 90%;
      padding: 0;
      margin: 5px;
      color: #7b7474;
    }
  }
  img {
    width: 170px;
    height: 170px;
  }
}
.price {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  width: 90%;
  padding: 10px;
  span {
    color: red;
  }
  div {
    background-color: #b0352f;
    padding: 7px 7px;
    border-radius: 10px;
    color: #fff;
  }
}
.active {
  color: red;
}
</style>